<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>骡窝窝系统管理平台</title>
    <#include "../common/header.ftl"/>
    <script type="text/javascript" src="/js/plugins/My97DatePicker/WdatePicker.js"></script>
    <script src="/js/plugins/ckeditor/ckeditor.js"></script>

    <style type="text/css">

        .content p{
            line-height: 25px;
            opacity: 0.75;
            font-size: 16px;
            margin-bottom: 15px;
        }


        .content h4 {
            font-weight: bold;
            line-height: 1.333em;
            margin: 5px 0px;
            padding: 5px 0;
            font-size: 16px;
        }

        .content img {
            width: 100%;
            height: auto;
            box-sizing: border-box;
        }

    </style>
    <script type="text/javascript">
        $(function(){
            $("#pagination").twbsPagination({
                totalPages:${pageInfo.pages}||1,
                visiblePages:5,
                startPage:${qo.currentPage},
                first:"首页",
                prev:"上一页",
                next:"下一页",
                last:"尾页",
                onPageClick:function(event,page){
                $("#currentPage").val(page);
                $("#searchForm").submit();
                }
            });

            $("#query").click(function(){
                $("#currentPage").val(1);
                $("#searchForm").submit();
            });

            //点击查看按钮
            $(".showBtn").click(function(){
                var id = $(this).data('tid');

                //获取该文章的内容
                $.get('/news/getContentById.do',{id:id},function (data) {
                    if(data){
                       $("#newsModal .modal-body").html(data.content);
                    }
                    $("#newsModal").modal("show");
                });
            });

            // 使用jQueryform修改模态框的提交方式-ajax方式,在表单提交之前
            $('#editForm').ajaxForm(function (data) {
                if (data.success) {
                    // 操作成功,刷新页面
                    location.reload();
                } else {
                    alert(data.msg);
                }
            });

            //初始化ckeditor
            var ck = CKEDITOR.replace( 'editor1' );

            //模态框的表单提交
            $("#saveBtn").click(function() {
                //获取编辑器中的内容,设置到textarea里面
                var data = ck.getData();
                $("#editor1").html(data);
                //提交表单
                $("#editForm").submit();
            });


            $(".inputBtn").click(function () {
                //1:先清空模态框的数据,再来做操作
                $('#inputModal input').val('');
                $('#inputModal select').val('');
                $('#inputModal img').attr('src','');
                //2:获取当前按钮中的自定义JSON对象
                var obj = $(this).data("json");
                console.log(obj);
                //3:只有编辑按钮才做数据回显
                if (obj) {
                    $("#inputModal input[name='id']").val(obj.id);
                    $("#inputModal input[name='title']").val(obj.title);
                    $("#inputModal input[name='subtitle']").val(obj.subtitle);
                    $("#inputModal select[name='state']").val(obj.state);
                    $("#inputModal input[name='coverUrl']").val(obj.coverUrl);
                    $("#coverImg").attr('src',obj.coverUrl);

                    //回显攻略文章内容
                    $.get('/news/getContentById.do',{id:obj.id},function(data){
                        ck.setData(data.content);
                    })


                }
                $("#inputModal").modal('show');
            })
        });


    </script>
    <style>
        #newsModal img{
            width: 100%;
        }
        #newsModal .modal-body{
            max-height: 600px;
            overflow-y: auto;
        }
    </style>
</head>

<body>
<div class="container">
<#include "../common/top.ftl"/>
    <div class="row">
        <div class="col-sm-3">
		<#assign currentMenu = "travel" />
				<#include "../common/menu.ftl" />
        </div>
        <div class="col-sm-9">
            <div class="page-header">
                <h3>日报管理</h3>
            </div>
            <div class="row">
                <!-- 提交分页的表单 -->
                <form id="searchForm" class="form-inline" method="post" action="/news/list.do">
                    <input type="hidden" name="currentPage" id="currentPage" value="1"/>
                    <div class="form-group">
                    </div>
                    <div class="form-group">
                        <label>关键字</label>
                        <input class="form-control" type="text" name="keyword" value="${(qo.keyword)!''}">
                    </div>
                    <div class="form-group">
                        <button id="query" type="button" class="btn btn-success"><i class="icon-search"></i> 查询</button>
                        <a href="javascript:" class="btn btn-success inputBtn">添加日报</a>
                    </div>
                </form>
            </div>
            <div class="row">
                <table class="table">
                    <thead>
                    <tr>
                        <th>标题</th>
                        <th>副标题</th>
                        <th>封面</th>
                        <th>发布时间</th>
                        <th>状态</th>
                    </tr>
                    </thead>
                    <tbody>
					<#list pageInfo.list as vo>
                    <tr>
                        <td>${vo.title!""}</td>
                        <td>${vo.subtitle!""}</td>
                        <td><img src='${vo.coverUrl!""}' width="50px"/></td>
                        <td>${(vo.commendTime?string('yyyy-MM-dd HH:mm:ss'))!""}</td>
                        <td>
                            <#if vo.state == 0>
                                推荐
                            <#elseif vo.state == 1>
                                普通
                            </#if>
                        </td>
                        <td>
                            <a href="javascript:void(0);" class="showBtn"  data-tid="${vo.id}">查看内容</a>
                        </td>
                        <td>
                            <a href="javascript:" class="btn btn-sm btn-success inputBtn" data-json='${vo.json}'>
                                <span class="glyphicon glyphicon-edit"></span> 修改
                            </a>
                        </td>
                    </tr>
					</#list>
                    </tbody>
                </table>

                <div style="text-align: center;">
                    <ul id="pagination" class="pagination"></ul>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="newsModal" class="modal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">查看内容</h4>
            </div>
            <div class="modal-body content">
            </div>
            <div class="modal-footer">
                <a href="javascript:void(0);" class="btn" data-dismiss="modal" aria-hidden="true">关闭</a>
            </div>
        </div>
    </div>
</div>
<#--新增/修改-->
<div id="inputModal" class="modal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">编辑/增加</h4>
            </div>
            <div class="modal-body">
                <form id="editForm" class="form-horizontal" method="post" action="/news/saveOrUpdate.do" enctype="multipart/form-data">
                    <input type="hidden" name="id">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">标题</label>
                        <div class="col-sm-7">
                            <input type="text" class="form-control"name="title">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">副标题</label>
                        <div class="col-sm-7">
                            <input type="text" class="form-control"name="subtitle">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">封面</label>
                        <div class="col-sm-7">
                            <img id="coverUrl" width="100%"/>
                            <input type="file" class="form-control" name="file" >
                            <input type="hidden" name="coverUrl" ><#--传后台-->
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">状态</label>
                        <div class="col-sm-7">
                            <select id="state" class="form-control" autocomplete="off" name="state" >
                                <option value="0">推荐</option>
                                <option value="1">普通</option>
                            </select>
                        </div>
                    </div>
                    <textarea name="strategyContent.content" id="editor1" ></textarea>
                </form>
            </div>
            <div class="modal-footer">
                <a href="javascript:void(0);" class="btn btn-success" id="saveBtn" aria-hidden="true">保存</a>
                <a href="javascript:void(0);" class="btn" data-dismiss="modal" aria-hidden="true">关闭</a>
            </div>
        </div>
    </div>
</div>
</body>
</html>